package com.yangye.pisecurity.handler;

import com.yangye.picommon.enums.PiResultEnum;
import com.yangye.picommon.model.PiResult;
import com.yangye.picommon.utils.RespUtil;
import org.springframework.security.access.AccessDeniedException;
import org.springframework.security.web.access.AccessDeniedHandler;
import org.springframework.stereotype.Component;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

/**
 * 权限认证失败处理器
 * @author yangye
 * @date 2019/8/20
 */
@Component
public class AuthenticationAccessDeniedHandler implements AccessDeniedHandler {
	@Override
	public void handle(HttpServletRequest request, HttpServletResponse response, AccessDeniedException e) throws IOException {
		RespUtil.writeJson(response, PiResult.fail(PiResultEnum.PERMISSION_DENIED));
	}
}
